
function consistSting(allowed:string,world:Array<string>):number{
    let sum:number=0
    world.forEach((item)=>{
        const newArr = item.split('')
        if(newArr.every((item)=>allowed.indexOf(item)!==-1)){
            sum++
        }
    })
    return sum
}
console.log(consistSting('ab',['ab','db','aab','ccd']));


function searurl(url:string){
    const paramstr=url.split('?')[1]
    const parr = paramstr.split('&')
    let obj = {}
    parr.forEach((item:string)=>{
        const key = item.split('=')[0]
        const value = item.split('=')[1]
        const newobj={
            [key]:value
        }
        obj={
            ...obj,
            ...newobj,
        }
    })
    return obj
}

console.log(searurl('http://www.info.com?name=哈哈&age=12&address=考试&sex=男'));


function func(price:number[]){
    let profit=0;
    for(let i = 1;i<price.length;i++){
        let tmp = price[i]-price[i-1];
        if(tmp>0)profit+=tmp
    }
    return profit
}
console.log(func([7,5,8,1,2]));


function single(nums:number[]){
    let num=-1
    for(let i = 0;i<nums.length;i++){
        if(nums.indexOf(nums[i])==nums.lastIndexOf(nums[i])){
            num=nums[i]
        }
    }
    return num
}
console.log(single([1,2,3,4,5,3,2]));

function flat<T>(arr:Array<T>,k=1):Array<T>{
    let newArr:Array<T> =[]
    arr.forEach((item:T)=>{
        if(Array.isArray(item)&& k>1){
            newArr=newArr.concat(flat(item,k-1))
        }else{
            newArr=newArr.concat(item)
        }
    })
    return newArr
}

console.log(flat([1,[2,3,[4,5]]],1));

